package com.builder.demo00;

import java.util.ArrayList;
import java.util.List;

/**
 * 抽象产品类: 声明产品零部件,并接收组装规则来组装这些零部件,具体的产品类负责生产零部件,由导演类Director来按照客户需求提供不同产品
 */
public abstract class Car implements ICar{

    private List<String> sequence = new ArrayList<>();

    // 组装启动装置业务的声明
    protected abstract void start();

    // 组装刹车系统业务的声明
    protected abstract void stop();

    // 组装喇叭系统业务的声明
    protected abstract void alarm();

    protected abstract void engineBoom();

    //
    public final void run(){
        for (String s : sequence) {
            if (s.equalsIgnoreCase("start")) {
                this.start();
            }else if(s.equalsIgnoreCase("stop")){
                this.stop();
            }else if(s.equalsIgnoreCase("alarm")){
                this.alarm();
            }else if(s.equalsIgnoreCase("engine boom")){
                this.engineBoom();
            }
        }
    }

    public final void setSequence(List<String> sequence){
        this.sequence = sequence;
    }

}
